package com.lemon.smartsafety.rayeye.adapter;

import android.support.annotation.NonNull;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafety.rayeye.entity.FaultFireListI;
import com.lemon.smartsafety.utils.common.DateUtils;
import com.lemon.smartsafety.utils.common.StringUtils;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.bingoogolapple.badgeview.BGABadgeLinearLayout;
import cn.bingoogolapple.badgeview.BGABadgeTextView;
import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by Cooliean on 16/3/29.
 */
public class FFListAdapter extends LemonRcvAdapter<FaultFireListI> {
    private RecyclerTClickListener<FaultFireListI> mListener;

    public FFListAdapter(List<FaultFireListI> data, RecyclerTClickListener<FaultFireListI> listener) {
        super(data);
        this.mListener = listener;
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new InnerItem();
    }

    public class InnerItem implements AdapterItem<FaultFireListI> {


        @Bind(R.id.imageIcon)
        ImageView            imageIcon;
        @Bind(R.id.itemText)
        BGABadgeTextView     itemText;
        @Bind(R.id.itemPointDesc)
        TextView             itemPointDesc;
        @Bind(R.id.itemTime)
        TextView             itemTime;
        @Bind(R.id.bga_content_layout)
        BGABadgeLinearLayout bgaContentLayout;
        @Bind(R.id.itemSubText)
        TextView             itemSubText;
        @Bind(R.id.ripple)
        LinearLayout ripple;


        private FaultFireListI mData;
        private int            mPosition;


        @Override
        public int getLayoutResId() {
            return R.layout.item_rayeye_item_list;
        }

        @Override
        public void bindViews(View root) {
            ButterKnife.bind(this, root);
        }

        @Override
        public void setViews() {
            ripple.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (mListener != null) {
                        mListener.onItemClick(mData, mPosition);
                    }
                }
            });
         /*   ripple.setOnRippleCompleteListener(new RippleView.OnRippleCompleteListener() {
                @Override
                public void onComplete(RippleView rippleView) {
                    if (mListener != null) {
                        mListener.onItemClick(mData, mPosition);
                    }
                }
            });*/
        }

        @Override
        public void handleData(FaultFireListI data, int position) {
            mData = data;
            mPosition = position;

            itemText.setText(data.getTitleI());

            if (StringUtils.nullValue(data.getPointDescI()).length() == 0) {
                itemPointDesc.setVisibility(View.GONE);
            }else{
                itemPointDesc.setVisibility(View.VISIBLE);
                itemPointDesc.setText(data.getPointDescI());
            }

            itemTime.setText(DateUtils.getStringByFormat(data.getTimeI(), DateUtils.dateFormatYMDHMS));

            itemSubText.setText(data.getDescType().getCharSeq());
        }
    }
}
